﻿Module GlobalVars
    Public db As New DbConnect
    Public nv As New clsNhanVien 'day la doi tuong nhan vien ne
    Public Function EscapeString(ByVal str As String) As String
        Return str.Replace("'", "''")
        'select * from nhanvien where manv = 'm' or ''=''
    End Function
    Public Sub SetCbBox(ByVal cb As ComboBox, ByVal dispmem As String, _
                             ByVal valmem As String, ByVal dt As DataTable)
        cb.DisplayMember = dispmem
        cb.ValueMember = valmem
        cb.DataSource = dt
    End Sub
    Public Sub ShowChildForm(ByVal parent As Form, ByVal child As Form)
        
        For i As Integer = 0 To parent.MdiChildren.Length - 1
            If parent.MdiChildren(i).Name = child.Name Then
                parent.MdiChildren(i).Activate() 'neu co thi kich hoat
                Exit Sub
            End If
        Next
        'neu chua co thi gan parent chua form con = form cha
        child.MdiParent = parent
        child.Show()
    End Sub
    Public Sub ChiNhapSo(ByVal sender As Object, ByVal e As KeyPressEventArgs)
        If Not (Char.IsNumber(e.KeyChar) Or Char.IsControl(e.KeyChar)) Then 'neu la so hoac ki tu dieu khien (delete, backspace) 
            e.Handled = True 'chan lai
        End If
    End Sub
    Public Function DatagridToTable(ByVal dgv As DataGridView) As DataTable
        Dim dt As New DataTable
        dt = TryCast(dgv.DataSource, DataTable)
        Return dt
    End Function
End Module
